<template>
  <div>
    <el-table :data="list">
      <el-table-column
        type="index"
        label="#"
        width="width"
      />
      <el-table-column
        prop="des"
        label="链接描述"
        width="width"
      />
      <el-table-column

        label="链接图片"
        width="width"
      >
        <template slot-scope="{row}">
          <img :src="showImgUrl(row.img)" width="100px" alt="">
        </template>
      </el-table-column>
      <el-table-column
        label="链接类型"
        width="width"
      >
        <template slot-scope="{row}">
          <el-button type="success" plain size="small" class="el-icon-eleme">{{ row.type === '1'? '文字链接': '图片链接' }}</el-button>
        </template>
      </el-table-column>

      <el-table-column
        prop="url"
        label="链接地址"
        width="width"
      />
      <el-table-column

        label="操作"
        width="width"
      >
        <template slot-scope="{row}">
          <el-button type="success" plain @click="getlinkInfoApi(row.id)">编辑</el-button>
          <el-button type="danger" plain @click="dellinkInfoApi(row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { dellinkInfoApi, getlinkInfoApi } from '@/api/adv_link'
import bus from '@/components/bus'
export default {
  name: 'ImgLink',
  props: {
    list: {
      type: Array,
      default: () => {}
    }
  },
  data() {
    return {

    }
  },
  computed: {
  },
  created() {

  },
  methods: {
    showImgUrl(url) {
      return process.env.VUE_APP_BASE_API + '/' + url
    },
    // 编辑
    async   getlinkInfoApi(id) {
      const res = await getlinkInfoApi({ id })
      res.img = this.showImgUrl(res.img)
      bus.$emit('data', res)
    },
    // 删除
    async dellinkInfoApi(id) {
      await this.$confirm('确让删除吗？')
      await dellinkInfoApi({ id })
      this.$message.success('删除成功')
      this.$emit('getlinkListApi')
    }
  }
}
</script>

<style>

</style>
